<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <button id="quan">全选</button>
      <button id="bu">不选</button>
      <button id="fan">反选</button>
    </div>

    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />
    <input type="checkbox" name="" id="" />

    <script>
      var btn = document.getElementsByTagName("button");
      var inp = document.getElementsByTagName("input");
      for (var i = 0; i < btn.length; i++) {
        btn[i].onclick = function () {
          if (this.innerHTML === "全选") {
            for (var k = 0; k < inp.length; k++) {
              inp[k].checked = true;
            }
          } else if (this.innerHTML === "不选") {
            for (var k = 0; k < inp.length; k++) {
              inp[k].checked = false;
            }
          }else if(this.innerHTML==="反选"){
            for (var k = 0; k < inp.length; k++) {
              inp[k].checked !== inp[k].checked;
            }
          }
        };
      }
    </script>
  </body>
</html>
